package player

import (
	"GameServer/Common/utils"
	"GameServer/Game/errors"
	"GameServer/Game/lib"
	"GameServer/Game/sp"
)

// 8601 委托信息请求
func (p *Player) EntrustActivRequest(req *sp.EntrustActivRequest) (res *sp.EntrustActivResponse, err error) {
	activ := lib.GetEAActiv()
	nowUnix := utils.TNow().Unix()
	if nowUnix < activ.BeginTime || activ.EndTime < nowUnix {
		res = &sp.EntrustActivResponse{}
		return
	}
	eag := lib.GetEntrustActiv(p.User)
	res = &sp.EntrustActivResponse{
		Tid:       eag.Tid,
		BeginTime: eag.BeginTime,
		EndTime:   eag.EndTime,
		Issue:     eag.Issue,
		Honor:     eag.Honor,
		HonorLst:  eag.HonorLst,
		EInfo:     lib.FormatEntrustInfo(eag.EntrTask),
	}
	return
}

// 8602 委托奖励领取
func (p *Player) EntrustRewardRequest(req *sp.EntrustRewardRequest) (res *sp.EntrustRewardResponse, err error) {

	uProp, resGoods, boxResList, err := lib.GetEntrustReward("EntrustRewardRequest", p.User, req.Tid, req.StageNum, p.Send)
	if err != nil {
		res = &sp.EntrustRewardResponse{
			Errcode: errors.ErrCode(err),
		}
		return
	}

	res = &sp.EntrustRewardResponse{
		Res:    lib.FormatGoodsInfoSps(resGoods),
		BoxRes: lib.FormatBoxResSps(boxResList),
	}

	p.TimelyUpdateProp(req.GetType(), uProp)
	utils.AsyncFunc(func() {
		p.UpdateProp(req.GetType(), uProp)
	})
	return
}
